﻿using Irony.Interpreter;
using Irony.Interpreter.Ast;
using Irony.Parsing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppServidor
{
   class XmlGrammar:Grammar
    {

        public XmlGrammar() {
            StringLiteral cad = TerminalFactory.CreateCSharpString("cad");
            StringLiteral caracter = TerminalFactory.CreateCSharpChar("caracter");
            NumberLiteral num = TerminalFactory.CreateCSharpNumber("num");
            IdentifierTerminal id = TerminalFactory.CreateCSharpIdentifier("id");
           

            NonTerminal xml = new NonTerminal("xml"),
                       nodo = new NonTerminal("nodo"),
                 
                       lnodo = new NonTerminal("lnodo"),
                    
                      valor = new NonTerminal("valor");
                 MarkPunctuation( "<", "/", ">");
             
                 xml.Rule = nodo;
                 nodo.Rule =  ToTerm("<") + id + ToTerm(">") + valor + ToTerm("<") + ToTerm("/") + id + ToTerm(">")
                           | ToTerm("<") + id + ToTerm(">") + lnodo + ToTerm("<") + ToTerm("/") + id + ToTerm(">")
                       ;
             
            lnodo.Rule=lnodo +nodo 
                      |nodo;
        
            valor.Rule = cad | num | caracter | id;
            this.Root = xml;
        }
    }
}

